/******************************************************************************
 * Copyright (C) 2016  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#include "node/util/option.h"

namespace node {
	namespace util {

	option::option(const std::string& name, const std::string& short_name, const std::string& description)
    : _name(name), _short_name(short_name), _description(description)
    , _value(), _required(false), _has_argument(false), _valid(false)
  	{

  	}
  	option::~option(void)
  	{

  	}

  	const std::string& option::get_name(void) const
  	{
    	return _name;
  	}
  	const std::string& option::get_short_name(void) const
  	{
    	return _short_name;
  	}
  	const std::string& option::get_description(void) const
  	{
    	return _description;
  	}
  	const std::string& option::get_value(void) const
  	{
    	return _value;
  	}
  	void option::set_value(const std::string& value)
  	{
    	_value = value;
  	}
  	bool option::is_requried(void) const
	{
		return _required;
	}
	option& option::set_required(bool requried)
  	{
    	_required = requried;
        return *this;
  	}
  	bool option::has_argument(void) const
  	{
    	return _has_argument;
  	}
	option& option::set_has_argument(bool has_argument)
  	{
    	_has_argument = has_argument;
        return *this;
  	}
  	bool option::is_valid(void) const
  	{
    	return _valid;
  	}
  	void option::set_is_valid(bool valid)
  	{
    	_valid = valid;
  	}

  	bool option::match_name(std::string& name) const
  	{
    	return ((name.length() > 2) && (name[0] == '-') 
      	&& (name[1] == '-') && (_name.compare(&name[2]) == 0));
  	}
  	bool option::match_short_name(std::string& short_name) const
  	{
    	return ((short_name.length() > 1) && (short_name[0] == '-')
      	&& (_short_name.compare(&short_name[1]) == 0));
  	}

}}

